<?php

namespace App\Service\Message\v1_3_0;

use App\Model\CloseFriend;
use App\Model\User;
use App\Model\UserChat;
use App\Model\UserMsgLog;
use App\Service\BaseService;

/**
 * 过滤无效账号
 */
class FilterMsgAccountsService extends BaseService
{
    public function handle()
    {
        $userId = $this->getUserId();
        if (User::checkOfficial($userId)) return ['list' => []];
        $imAccounts = $this->request->input('im_accounts', '');
        $imAccounts = explode(',', $imAccounts);
        $imAccounts = array_slice($imAccounts, 0, 500);
        // return ['list' => array_slice($imAccounts, 0, 10)];
        $chatUserIds = User::getUserIdByIm($imAccounts, 'kv');
        //24小时内有回复过的
        $msgbackUids = UserChat::getMsgUserIds($userId, intval(env('CLEAR_MSG_OFFTIME', 86400)));
        //密友列表
        $closeUids = CloseFriend::getFrdList($userId);
        $noBackUids = array_diff($chatUserIds, $msgbackUids, $closeUids);
        $noBackAccounts = array_keys($noBackUids);
        // log_user_result($userId, $noBackUids);
        return ['list' => $noBackAccounts];
    }
}
